package 双指针;

/**
 * @author zhengTao
 * @version 1.0
 * @description: 有序数组的平方
 * @date 2022/10/14 15:12
 */
public class Demo977 {
    public int[] sortedSquares(int[] nums) {
        int left=0,right=nums.length-1;
        int length = nums.length;
        int[] num=new int[length];
          while (left<=right){
              if(Math.abs(nums[left])>Math.abs(nums[right])){
                  num[--length]=nums[left]*nums[left];
                  left++;
              }else {
                  num[--length]=nums[right]*nums[right];
                  right--;
              }
          }
          return num;
    }
}
